from googlevoice import Voice
from googlevoice.util import input
from ad2usb import ad2usb
import time
import sys

voice = Voice()

if len(sys.argv) < 5:
        print("\r\n")
        print("AD2USB SMS Script v0.01")
        print("----------------------------------------")
        print("Command Line Arguments:")
        print("sms.py comport email password phone_to_text 2_step_auth_pin")
	print("\r\n")
        sys.exit()

device = sys.argv[1]
email = sys.argv[2]
password = sys.argv[3]
phone = sys.argv[4]

if len(sys.argv) < 6:
   	voice.login(email,password)
else:
	pin = sys.argv[5]
	voice.login(email,password,pin)

#phoneNumber = input('Number to send message to: ')

usb = ad2usb()
usb.openPort(device)
print "Opened\r\n"
var = 200
result = 0
lastResult = 0


while 1:
    usb.Process()
    result = usb.getStatus()
    time.sleep(.1)
    var=var-1
    output = ""

    if result == 0: # if the current result is UNKNOWN, do not process
       continue
    if lastResult == result: # if this result is different than the previous then proceed
       continue  
    else:
       lastResult = result
    if result == 0:
        pass
	output = ""
    elif result == 1:
	output = "ready"
    elif result == 2:
  	output = "armed_away"
    elif result == 3:
        output = "armed_stay"
    elif result == 4:
        output = "triggered"
    elif result == 5:
        output = "siren"
    else:
        continue

    if output != "":

   	print "\r\n"
    	print output
    	print "\r\n"

    voice.send_sms(phone,output)


